package com.oa.ylms.apps.actions.archives;

import java.io.InputStream;

import org.apache.struts2.ServletActionContext;

import com.oa.ylms.apps.actions.BasicAction;
import com.oa.ylms.apps.business.archives.IAvatarInfoService;
import com.oa.ylms.apps.entity.archives.AvatarInfoValue;

@SuppressWarnings("serial")
public class GetPhotoAction extends BasicAction {

	private IAvatarInfoService avatarService;
	private AvatarInfoValue avatarInfo;
	
	private Integer avatarId;
	private String gender;
	
	public String execute() throws Exception {
		return SUCCESS;
	}
	
	public InputStream getImage() throws Exception{
		InputStream imageStream = null;
		//gender = new String(gender.getBytes("ISO-8859-1"),"UTF-8");
		if(avatarId != null)
			avatarInfo = avatarService.queryByAvatarId(avatarId);
		if(avatarInfo.getAvatarImage() != null)
			imageStream = avatarInfo.getAvatarImage().getBinaryStream();
		else{
			if("女".equals(gender))
				imageStream = ServletActionContext.getServletContext().getResourceAsStream("/WEB-INF/UploadFiles/women_main.gif");
			else
				imageStream = ServletActionContext.getServletContext().getResourceAsStream("/WEB-INF/UploadFiles/men_main.gif");
		}
		
		return imageStream;
	}
	
	public Integer getAvatarId() {
		return avatarId;
	}

	public void setAvatarId(Integer avatarId) {
		this.avatarId = avatarId;
	}

	public void setAvatarService(IAvatarInfoService avatarService) {
		this.avatarService = avatarService;
	}

	public IAvatarInfoService getAvatarService() {
		return avatarService;
	}

	public void setAvatarInfo(AvatarInfoValue avatarInfo) {
		this.avatarInfo = avatarInfo;
	}

	public AvatarInfoValue getAvatarInfo() {
		return avatarInfo;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	public String getGender() {
		return gender;
	}
	
}
